
using QdbUnit.Extensions;
using QdbUnit.Extensions.Fixtures;
using Qdb.Config;
using Qdb.Ext;
using Qdb.IO;
using Qdb.Tests.Common.Exceptions;

namespace Qdb.Tests.Common.Exceptions
{
	public class QdbIOExceptionTestCaseBase : AbstractQdbTestCase, IOptOutMultiSession
		, IOptOutTA
	{
		private ExceptionSimulatingStorage _storage;

		protected override void Configure(IConfiguration config)
		{
			config.LockDatabaseFile(false);
			_storage = new ExceptionSimulatingStorage(new FileStorage(), new _IExceptionFactory_19
				());
			config.Storage = _storage;
		}

		private sealed class _IExceptionFactory_19 : IExceptionFactory
		{
			public _IExceptionFactory_19()
			{
			}

			public void ThrowException()
			{
				throw new QdbIOException();
			}

			public void ThrowOnClose()
			{
			}
		}

		/// <exception cref="System.Exception"></exception>
		protected override void QdbSetupBeforeStore()
		{
			TriggerException(false);
		}

		/// <exception cref="System.Exception"></exception>
		protected override void QdbTearDownBeforeClean()
		{
			TriggerException(false);
		}

		protected virtual void TriggerException(bool value)
		{
			_storage.TriggerException(value);
		}
	}
}
